package org.linuxsogood.boot.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author honway.liu
 * @date 2019/12/4 9:03 下午
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 */
@Aspect
@Slf4j
@Component
public class ControllerAspect {

    @Pointcut("execution(public String org.linuxsogood.boot.controller.IndexController.index())")
    public void indexPoint(){}

    @Pointcut("execution(public String org.linuxsogood.boot.controller.IndexController.params(String))")
    public void paramPoint(){}


    @Before("indexPoint()")
    public void indexProcess(JoinPoint joinPoint) {
        log.info("index is execute...");
    }

    @Before("paramPoint()")
    public void paramsProcess(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        String param1 = (String) args[0];
        log.info("params: {}", param1);
        log.info("params is execute...");
    }
}
